JSLoadUtil.loadOnlyOnce("js/Constants.js");
JSLoadUtil.loadOnlyOnce("js/util/OOUtils.js");
JSLoadUtil.loadOnlyOnce("js/util/kdtree/KDTree.js");
JSLoadUtil.loadOnlyOnce("js/renderer/CoordinatesUtil.js");
JSLoadUtil.loadOnlyOnce("js/objects/ObjectBag.js");
JSLoadUtil.loadOnlyOnce("js/input/InputHandler.js");
JSLoadUtil.loadOnlyOnce("js/Model.js");

var nodeDistanceFunction = function(obj1, obj2){
  "use strict";
  return Math.sqrt(Math.pow(obj1.x - obj2.x, 2) +  Math.pow(obj1.y - obj2.y, 2));
};
var nodeDimensionAttributes=["x","y"];
var tree = new KDTree(null,nodeDistanceFunction,nodeDimensionAttributes);
tree.insert(new Scout(6,8));
tree.insert(new Scout(9,8));
var theScout=new Scout(3,7);
tree.insert(theScout);
tree.insert(new Scout(5,3));
tree.insert(new Scout(8,4));
console.log("tree:"+tree);

//Find closest
var closest = tree.findNearest({x:2, y:2},2,100);
console.log("closest:"+closest);

//Move node
tree.updateNodeCoordinates(theScout, {x:2.1, y:2.1});
console.log("tree:"+tree);

//Find closest again
var closest = tree.findNearest({x:2, y:2},2,100);
console.log("closest:"+closest);

//Print results to div.
outDiv.innerHTML="<u>Tree:</u><br/>"+tree+"<br/><u>Nearests:</u><br/>"+closest;